package com.wpc.validate;

import java.util.ArrayList;
import java.util.List;

import com.wpc.form.ProductForm;

public class ProductValidate {

	public static List<String> productValidate(ProductForm productForm) {
		List<String> errors = new ArrayList<>();

		String name = productForm.getName();
		if (name == null || name.trim().isEmpty()) {
			errors.add("产品名称不能为空！");
		}

		String price = productForm.getPrice();
		if (price == null || price.trim().isEmpty()) {
			errors.add("产品价钱不能为空！");
		} else {
			try {
				Float.parseFloat(price);
			} catch (NumberFormatException e) {
				errors.add("价钱为数字！");
			}
		}
		return errors;
	}

}
